﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using Core.Library;
using DataObject;
using DataObject.Category;
using DataObject.Product;
using DataObject.Cart;

namespace KMT.Controls.Common
{
    public partial class NewProduct : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ListTopHightlightProduct();
        }

        private void ListTopHightlightProduct()
        {
            rptProduct.DataSource = ProductController.Product_ListTopHightlightProduct(SettingValues.PageSize_12);
            rptProduct.DataBind();
        }

        protected void rptProduct_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Utility.RptProduct_NewProduct_SaleProduct(sender, e);

            /*
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                var sb = new StringBuilder();                                

                var ltDetail = (Literal)e.Item.FindControl("ltDetail");               
                 
                var productId      = ConvertUtility.ToInt32(((DataRowView)e.Item.DataItem).Row["ProductId"]);
                var unsignCategory = ((DataRowView)e.Item.DataItem).Row["UnsignCategory"].ToString();
                var unsignProduct  = ((DataRowView)e.Item.DataItem).Row["UnsignProduct"].ToString();                
                var productName    = ((DataRowView)e.Item.DataItem).Row["ProductName"].ToString();

                var pHref = UrlHelpers.ProductDetail(unsignCategory, productId, unsignProduct); 

                var imgHref = string.Format("{0}/Thumb.ashx?Id={1}&tId={2}&Size={3}", 
                                                Constants.ThumbImage, productId, (int)CategoryType.Product, Constants.ThumbImageSizeList);

                var specialPrice    = ConvertUtility.ToDecimal(((DataRowView)e.Item.DataItem).Row["SpecialPrice"]);
                var unitPrice       = ConvertUtility.ToDecimal(((DataRowView)e.Item.DataItem).Row["UnitPrice"]);

                sb.AppendFormat("<a href=\"{0}\" title=\"{1}\" class=\"product-image\"><img src=\"{2}\" alt=\"\" /></a>", pHref, productName, imgHref);               
                
                sb.Append("<div class=\"new-description\">");
                sb.Append("<div class=\"price-box\">");
                sb.AppendFormat("<h3><a href=\"{0}\" title=\"{1}\">{2}</a></h3>", pHref, UnicodeUtility.CutStrExper(productName, Constants.CutString), productName);

                if (specialPrice > 0)
                {
                    sb.Append("<p class=\"old-price\">");
                    sb.AppendFormat("<span class=\"price-label\">Giá cũ:</span> <span class=\"price\">{0}</span>", Utils.FormatPrice(unitPrice));
                    sb.Append("</p>");

                    sb.Append("<p class=\"special-price\">");
                    sb.AppendFormat("<span class=\"price-label\">Giá đặc biệt:</span> <span class=\"price\">{0}</span>", Utils.FormatPrice(specialPrice));
                    sb.Append("</p>");
                }
                else
                {
                    sb.Append("<p class=\"special-price\">");
                    sb.AppendFormat("<span class=\"price-label\">Giá:</span> <span class=\"price\">{0}</span>", Utils.FormatPrice(unitPrice));
                    sb.Append("</p>");
                }

                sb.Append("</div>");
                sb.Append("<button type=\"button\" title=\"Thêm vào giỏ hàng\" class=\"button btn-cart\" onclick=\"\"><span><span>Đặt hàng</span></span></button>");
                sb.Append("<div style=\"clear: both;\"></div>");
                sb.Append("</div>");                

                ltDetail.Text = sb.ToString();
            }
            */
        }    
    }
}